package com.lineage.server.serverpackets;

import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Object;

public class S_Chat extends ServerBasePacket {
  private byte[] _byte;
  
  public S_Chat(L1PcInstance pc, String chat) {
    this._byte = null;
    buildPacket(pc, chat);
  }
  
  private void buildPacket(L1PcInstance pc, String chat) {
    writeC(81);
    writeC(0);
    writeD(pc.isInvisble() ? 0 : pc.getId());
    writeS(String.valueOf(String.valueOf(pc.getViewName())) + ": " + chat);
  }
  
  public S_Chat(L1NpcInstance npc, String chat) {
    this._byte = null;
    writeC(81);
    writeC(0);
    writeD(npc.isInvisble() ? 0 : npc.getId());
    writeS(String.valueOf(String.valueOf(npc.getNameId())) + ": " + chat);
  }
  
  public S_Chat(L1Object object, String chat) {
    this._byte = null;
    writeC(81);
    writeC(0);
    writeD(object.getId());
    writeS(chat);
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
